package com.yunxi.controller.sto;

import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.sto.pojo.StoTransportOrderApproveVO;
import com.yunxi.sto.pojo.StoTransportOrderDetailVO;
import com.yunxi.sto.pojo.StoTransportOrderStockInVO;
import com.yunxi.sto.pojo.StoTransportOrderVO;
import com.yunxi.sto.service.StoTransportOrderDubboService;
import io.swagger.annotations.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * <p>
 * 车辆发运单 前端控制器
 * </p>
 *
 * @author caoYong
 * @since 2019-05-29
 */
@RestController
@RequestMapping("/admin/stoTransportOrder")
@Api(tags = "sto:transportOrder", description = "车辆发运单接口")
public class StoTransportOrderController {
 private static final Logger logger = LoggerFactory.getLogger(StoTransportOrderController.class);

 @Autowired
 StoTransportOrderDubboService stoTransportOrderDubboService;

 @GetMapping("/page")
 @ApiOperation(value = "发运单查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult page(StoTransportOrderVO stoTransportOrderVO, Integer pageNum, Integer pageSize,@CurrentUser LoginInfo loginInfo) throws Exception {
  stoTransportOrderVO.setPartnerCode(loginInfo.getPartnerCode());
  return ResponseUtil.ok(stoTransportOrderDubboService.findPageByVO(stoTransportOrderVO,pageNum,pageSize));
 }

 @GetMapping("/detailPage")
 @ApiOperation(value = "发运单明细查询分页")
 @ApiImplicitParams({
         @ApiImplicitParam(paramType="query", name = "pageNum", value = "分页页码", required = true, dataType = "int"),
         @ApiImplicitParam(paramType="query", name = "pageSize", value = "分页数量", required = true, dataType = "int")
 })
 public ApiResult detailPage(StoTransportOrderDetailVO stoTransportOrderDetailVO, Integer pageNum, Integer pageSize) throws Exception {
  return ResponseUtil.ok(stoTransportOrderDubboService.detailPage(stoTransportOrderDetailVO,pageNum,pageSize));
 }

 @GetMapping("/load")
 @ApiOperation(value = "读取单个")
 @ApiImplicitParam(paramType="query", name = "transportOrderId", value = "主键id", required = true, dataType = "String")
 public ApiResult load(String transportOrderId, @CurrentUser LoginInfo loginInfo) throws Exception {
  return ResponseUtil.ok(stoTransportOrderDubboService.getById(transportOrderId));
 }

 @PostMapping("/receive")
 @ApiOperation(value = "确认收车")
 public ApiResult receive(@RequestBody @ApiParam(value = "主键id集合") List<String> list, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoTransportOrderDubboService.receive(list,loginInfo.getPartnerCode(),loginInfo.getRealName(),loginInfo.getUserCode());
  return ResponseUtil.ok("success");
 }

 @PostMapping("/stockIn")
 @ApiOperation(value = "入库")
 public ApiResult stockIn(@RequestBody StoTransportOrderStockInVO stoTransportOrderStockInVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoTransportOrderStockInVO.setStockInUser(loginInfo.getUserCode());
  stoTransportOrderStockInVO.setPartnerCode(loginInfo.getPartnerCode());
  stoTransportOrderDubboService.stockIn(stoTransportOrderStockInVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/approve")
 @ApiOperation(value = "审批")
 public ApiResult approve(@RequestBody StoTransportOrderApproveVO stoTransportOrderApproveVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoTransportOrderDubboService.approve(stoTransportOrderApproveVO);
  return ResponseUtil.ok("success");
 }

 /*@PostMapping("/save")
 @ApiOperation(value = "保存信息")
 public ApiResult save(@RequestBody StoTransportOrderVO stoTransportOrderVO, @CurrentUser LoginInfo loginInfo) throws Exception {
  stoTransportOrderDubboService.saveOrUpdate(stoTransportOrderVO);
  return ResponseUtil.ok("success");
 }

 @PostMapping("/del")
 @ApiOperation(value = "删除")
 public ApiResult del(@RequestBody List<StoTransportOrderVO> stoTransportOrderVOList) throws Exception {
  stoTransportOrderDubboService.removeByListVo(stoTransportOrderVOList);
  return ResponseUtil.ok("success");
 }*/

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(stoTransportOrderDubboService.findMapByList(params));
}*/
}
